#include<bits/stdc++.h>
using namespace std;bool Mbe;
const int IN=3e7;
char _i[IN],*_I=_i;
inline int rd(){
	for(;*_I<0x30;_I++);int x=0;
	for(;*_I>0x2f;_I++)x=(x<<1)+(x<<3)+(*_I^0x30);return x;
}
namespace MAOJUN{

const int N=1.5e6+5,MOD=1e9+7;
int n,k;
const int E=N<<1;
int tot=0,hd[N],to[E],nxt[E];
inline void Add(int u,int v){to[++tot]=v;nxt[tot]=hd[u];hd[u]=tot;}

typedef vector<int> vct;
vct*dp[N];
int dfc,dfn[N],id[N],dep[N],lg[N],st[22][N];
int fa[N],sn[N],ln[N];
void dfs1(int u,int f){
	fa[u]=f;dep[u]=dep[f]+1;st[0][dfn[u]=++dfc]=dfn[f];id[dfc]=u;
	for(int i=hd[u];i;i=nxt[i])if(int v=to[i];v^f){
		dfs1(v,u);ln[v]>ln[sn[u]]&&(sn[u]=v);
	}
	ln[u]=ln[sn[u]]+1;
}
int ds[N];
inline int fd(int x){for(;x^ds[x];x=ds[x]=ds[ds[x]]);return x;}
void dfs2(int u){
	dp[u][0].emplace_back(u);
	if(!sn[u])return;
	dp[sn[u]]=dp[u]+1;dfs2(sn[u]);
	for(int i=hd[u];i;i=nxt[i])if(int v=to[i];v^fa[u]&&v^sn[u]){
		dp[v]=new vct[ln[v]];dfs2(v);
		for(int i=0;i<ln[v];i++){
			if(0<=k-i-1&&k-i-1<ln[u]){
				int rt=fd(dp[u][k-i-1][0]);
				for(int x:dp[u][k-i-1])ds[fd(x)]=rt;
				for(int x:dp[v][i])ds[fd(x)]=rt;
				dp[v][i].clear();dp[u][k-i-1].clear();
				dp[v][i].emplace_back(rt);dp[u][k-i-1].emplace_back(rt);
			}
			for(int x:dp[v][i])dp[u][i+1].emplace_back(x);
		}
	}
	if(k<ln[u]){
		int rt=fd(u);for(int v:dp[u][k])ds[fd(v)]=rt;
		dp[u][k].clear();dp[u][k].emplace_back(rt);
	}
}
bool ck[N];int G[N],m1[N],m2[N];
void dfs4(int u){
	ck[u]|=ln[u]+G[u]>=k;
	for(int i=hd[u];i;i=nxt[i])if(int v=to[i];v^fa[u]){
		G[v]=max(G[u]+1,ln[v==m1[u]?m2[u]:m1[u]]+1);dfs4(v);
	}
}
inline int LCA(int u,int v){
	int l=dfn[u],r=dfn[v];if(l>r)swap(l,r);l++;
	int k=lg[r-l+1];return id[min(st[k][l],st[k][r-(1<<k)+1])];
}
vector<int>vc[N],g[N];
bool fl[N],ok;int f[N];
void dfs3(int u){
	f[u]=1e9;
	for(int v:g[u]){dfs3(v);if(!ok)return;f[u]=min(f[u],f[v]+dep[v]-dep[u]);}
	if(fl[u]){if(f[u]<k){ok=0;return;}f[u]=0;}
}
inline void main(){
	n=rd();k=rd();
	for(int i=1,u,v;i<n;i++){u=rd();v=rd();Add(u,v);Add(v,u);}
	iota(ds+1,ds+n+1,1);
	dfs1(1,0);dp[1]=new vct[ln[1]];dfs2(1);
	for(int i=2;i<=n;i++)lg[i]=lg[i>>1]+1;
	for(int k=1;1<<k<n;k++)for(int i=2;i+(1<<k)-1<=n;i++)
		st[k][i]=min(st[k-1][i],st[k-1][i+(1<<k-1)]);
	ln[0]=-N;
	for(int u=1;u<=n;u++){
		m1[u]=sn[u];
		for(int i=hd[u];i;i=nxt[i])
			if(int v=to[i];v^fa[u]&&v^sn[u]&&ln[v]>ln[m2[u]])m2[u]=v;
		ck[u]=ln[m1[u]]+ln[m2[u]]>=k-1;
	}
	dfs4(1);
	long long as=1;
	for(int i=1;i<=n;i++)
		if(ck[i])vc[fd(i)].emplace_back(i);
		else as=as*2%MOD;
	int cnt=0;
	for(int i=1;i<=n;i++)if(!vc[i].empty()){
		int s=vc[i].size();
		for(int u:vc[i])fl[u]=1;
		sort(vc[i].begin(),vc[i].end(),[&](int x,int y){return dfn[x]<dfn[y];});
		for(int j=s-1;j;j--)vc[i].emplace_back(LCA(vc[i][j-1],vc[i][j]));
		vc[i].emplace_back(1);
		sort(vc[i].begin(),vc[i].end(),[&](int x,int y){return dfn[x]<dfn[y];});
		vc[i].erase(unique(vc[i].begin(),vc[i].end()),vc[i].end());s=vc[i].size();
		for(int j=1;j<s;j++)g[LCA(vc[i][j-1],vc[i][j])].emplace_back(vc[i][j]);
		ok=1;dfs3(1);cnt+=ok;
		for(int u:vc[i]){g[u].clear();fl[u]=0;}
	}
	if(cnt)printf("YES\n%lld\n",cnt*as%MOD);
	else printf("NO\n0\n");
}

}bool Med;int main(){
#ifdef LOCAL
	freopen("down/life/life5.in","r",stdin);
	freopen("data.out","w",stdout);
	atexit([]{fprintf(stderr,"%.0lfms\n%lfMB\n",clock()*1000./CLOCKS_PER_SEC,(&Mbe-&Med)/1024./1024);});
#else
	freopen("life.in","r",stdin);
	freopen("life.out","w",stdout);
#endif
	fread(_i,1,IN,stdin);
	MAOJUN::main();
	return 0;
}